package com.tianma315.admin.produce.controller;


import java.util.Arrays;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import com.tianma315.admin.produce.VO.ProduceVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.produce.domain.ProduceTaskDO;
import com.tianma315.admin.produce.service.ProduceTaskService;

/**
 * 
 * <pre>
 * 生产任务
 * </pre>
 * <small> 2019-05-29 16:16:04 | Aron</small>
 */
@Controller
@RequestMapping("/produce/produceTask")
public class ProduceTaskController extends BaseController{
	@Autowired
	private ProduceTaskService produceTaskService;
	
	@GetMapping()
	@RequiresPermissions("produce:produceTask:produceTask")
	String ProduceTask(){
	    return "produce/produceTask/produceTask";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("produce:produceTask:produceTask")
	public Result<Page<ProduceVO>> list(Integer pageNumber, Integer pageSize, ProduceTaskDO produceTaskDTO){
		// 查询列表数据
        Page<ProduceVO> page = produceTaskService.getProduceVOPage(pageNumber,pageSize,produceTaskDTO);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("produce:produceTask:add")
	String add(){
	    return "produce/produceTask/add";
	}

	@GetMapping("/edit/{produceTaskId}")
	@RequiresPermissions("produce:produceTask:edit")
	String edit(@PathVariable("produceTaskId") Integer produceTaskId,Model model){
		ProduceTaskDO produceTask = produceTaskService.selectById(produceTaskId);
		model.addAttribute("produceTask", produceTask);
	    return "produce/produceTask/edit";
	}

	/**
	 * 跳转生产列表
	 * @param produceTaskId
	 * @param model
	 * @return
	 */
	@GetMapping("/produce/{produceTaskId}")
	String produce(@PathVariable("produceTaskId") Integer produceTaskId,Model model){
		model.addAttribute("produceTaskId", produceTaskId);
		return "produce/scList";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("produce:produceTask:add")
	public Result<String> save( ProduceTaskDO produceTask){
		if(produceTaskService.addProduceTaskDO(produceTask)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("produce:produceTask:edit")
	public Result<String>  update( ProduceTaskDO produceTask){
		produceTaskService.updateById(produceTask);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("produce:produceTask:remove")
	public Result<String>  remove( Integer produceTaskId){
		if(produceTaskService.deleteProduceTaskDO(produceTaskId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("produce:produceTask:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] produceTaskIds){
		produceTaskService.deleteBatchIds(Arrays.asList(produceTaskIds));
		for (int i = 0; i < produceTaskIds.length; i++) {
			produceTaskService.deleteProduceTaskDO(produceTaskIds[i]);
		}
		return Result.ok();
	}
	
}
